const compressPlugin=require('compression-webpack-plugin')
const path = require('path');
const apiMocker = require('mocker-api');

module.exports = {
  // 禁用eslint-loader
  publicPath:'',
  lintOnSave:false,
  devServer: {
    // proxy:'http://localhost:8888',
    host:'0.0.0.0',
    port:8080,
    before(app){
      apiMocker(app, path.resolve('./src/mock/index.js'))
    }
  },
  chainWebpack: config => {
    config.when(
      process.env.NODE_ENV === 'production',
      config => config.devtool('eval')
    );
    config.when(
      process.env.NODE_ENV === 'development',
      config => config.devtool('source-map')
    );
    // config.module.rule('min-image')
    //   .test(/\.(png|jpe?g|gif)(\?.*)?$/)
    //   .rule('file')
    //   .use('file-loader')
    //   .loader('file-loader')
    //   .end()
    //   .use('image-webpack-loader')
    //   .loader('image-webpack-loader')
    //   .options({ disable: process.env.NODE_ENV == 'development' ? true : false })
      
    config.plugin('compressPlugin')
      .use(compressPlugin, [{
        filename: '[path][base].gz',
        algorithm: 'gzip',
        test: /\.(js|css)$/, 
        threshold: 10240,
        minRatio: 0.8
      }]);
  }
}